<?php
/**
 * appRain v 0.1.x
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Team. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */


/**
 * Home page
 */
class homeController extends appRain_Base_Core
{
    // Controller Name
    public $name = "Home";
    public $dispatch =  Array(
                                'preDispatchExclude'=>array(),
                                'postDispatchExclude'=>array());

    /**
     * Function Call before Page action method each time
     */
    public function __preDispatch()
    {
		//App::Module('Session')->Delete('User');
    }

    /**
     * Function Call before Page action method each time
     */
    public function __postDispatch()
    {

    }

    /**
     * Render Home page
     * We have configure this page from
     * URI_Manager >> Boot_Router
     * to be Render as a starting page of the project
     */
    public function indexAction($id=null)
    {
        App::setUserStatusId(0);
        // Fetch data from static page manager and
        // set Page Meta Information.
        $homepage = $this->staticPageNameToMetaInfo('HomePage');
		$this->addons = Array('validation','defaultvalues');

        // Set value to template
        $this->set("selected","home");
		$this->set("homepage",$homepage);
    }

    /**
     * Create search result based on Definitions
     * and call back functions.
     */
    public function searchAction($srcstr = null, $page = 1)
    {
        // Attach Addons and Set meta information
        $this->addons = Array('defaultvalues');
        $staticpage = $this->staticPageNameToMetaInfo('search');

        // Fetch all search data definition in defintion
        // for Information Set and Category set
        $srcstr = isset($this->post['ss']) ? $this->post['ss'] : $srcstr;
        $srcData = App::Helper("Search")
                      ->setSmartPaging(true)
                      ->setPage($page)
                      ->setLimit(5)
                      ->setHLink($this->baseurl("/search/{$srcstr}"))
                      ->Search($srcstr);

        // Overwrite page title
        $this->page_title = "{$srcstr} {$this->page_title}";
        // Set Search data
        $this->set('srcstr', $srcstr);
        $this->set('srcarr', $srcData);
        // Set Common variables
        $this->set("section_title","Search Reasult");
        $this->set("selected","search");
    }

    public function serviceAction()
    {

    }

    public function service2Action()
    {

    }

    public function ratesAction()
    {

    }

    public function faqAction()
    {

    }
    public function tutorialAction()
    {

    }  
	
	public function portfolioAction($action=null, $id=null,$page = 1)
    {
		$this->addons = Array('defaultvalues','beforeafter');
		if($action == 'byport')
        {
            // Fetch a Single Portfolio from Information Set
            // by Portfolio Id
            $port = App::InformationSet()->findById($id);
            $this->set('port',$port);

            // Overwrite the page title
            $this->page_title = $port['title'];
        } else {
			$page = is_numeric($action) ? $action : 1;
			$pfolio = App::InformationSet('portfolio')
						->setPagination('Yes')
						->setSmartPaging(true)
						->setPage($page)
						->setHLink(App::Helper('Config')->baseurl("/portfolio"))
						->setLimit(2)
						->setNextCaption('Next >>')
						->setPrevCaption('<< Prev')
						->findAll("1 ORDER BY id DESC",Array(Array("status"=>"Public")));
			$this->set('pfolio',$pfolio);
		}
		$this->set("action",$action);
    } 
	
	public function bfrafterAction()
    {
		$this->addons = Array('beforeafter');
    }
    
}